25B - Phone numbers - CodeForces Solution


implementation *1100

Please click on ads to support us..

Python Code:

def insert(line, ind, s):
    line = line[:ind] + s + line[ind:]
    return line


size = int(input())
phoneNum = input()
i = size - 2 if size % 2 == 0 else size - 3
for i in range(i, 0, - 2):
    phoneNum = insert(phoneNum, i, '-')
print(phoneNum)

C++ Code:

#include<bits/stdc++.h>
#define lol ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define el "\n"
#define ll long long
#define MOD 1000000007
#define ld long double
using namespace std;

//INSANE

int main()
{
    lol
   int n; cin>>n;
   string s; cin>>s;
   if(n==2||n==3)
   {
    cout<<s;
   }
   else if(n%2==0)
   {
    for(int i=0;i<n;i++)
    {
        cout<<s[i];
        if(i%2==1&&i!=n-1)
        {
            cout<<'-';
        }
    }
   }
    else if(n%3==0)
   {
    for(int i=0;i<n;i++)
    {
        cout<<s[i];
        if(i%3==2&&i!=n-1)
        {
            cout<<'-';
        }
    }
   }
else
   {
    for(int i=0;i<n;i++)
    {
        cout<<s[i];
        if(i%3==1&&i!=n-1)
        {
            cout<<'-';
        }
    }
   }
   cout<<el;
   }




Comments

Submit
0 Comments
More Questions

1717D - Madoka and The Corruption Scheme
1296D - Fight with Monsters
729D - Sea Battle
788A - Functions again
1245B - Restricted RPS
1490D - Permutation Transformation
1087B - Div Times Mod
1213B - Bad Prices
1726B - Mainak and Interesting Sequence
1726D - Edge Split
1726C - Jatayu's Balanced Bracket Sequence
1726A - Mainak and Array
1613C - Poisoned Dagger
475B - Strongly Connected City
652B - z-sort
124B - Permutations
1496C - Diamond Miner
680B - Bear and Finding Criminals
1036E - Covered Points
1015D - Walking Between Houses
155B - Combination
1531A - Зингер | color
1678A - Tokitsukaze and All Zero Sequence
896A - Nephren gives a riddle
761A - Dasha and Stairs
1728B - Best Permutation
1728A - Colored Balls Revisited
276B - Little Girl and Game
1181A - Chunga-Changa
1728C - Digital Logarithm